<template>
  <view>
    <!-- parse <include src="../component/navigationBar.wxml"></include> -->
    <block>
      <view
          :style="'padding-top:' + nTop + 'px;height:' + nHeight + 'px;line-height:' + nHeight + 'px;--color:' + color + ';'"
          class="navigationBox">
        <view :style="'height:' + nHeight + 'px;top:' + nTop + 'px'" class="nBar">
          <navigator :openType="pages.length == 1 ? 'switchTab' : 'navigateBack'"
                     :url="pages.length == 1 ? '/pages/index/index4' : ''" class="ico"
                     hoverClass="none">
            {{ pages.length == 1 ? '' : '' }}
          </navigator>
          <view class="title">{{ nTitle }}</view>
        </view>
      </view>
    </block>
    <view :style="'margin-top:' + nTH + 'px;--color:' + color + ';--rgbcolor:' + rgbcolor + ';'" class="T">
      <view class="h2">{{ D.title }}</view>
      <view class="h6">
        <navigator class="a" hoverClass="none" openType="reLaunch" url="/pages/index/index4">
          <image :src="D.logo" mode="aspectFill"></image>
          {{ D.siteName }}
        </navigator>
        <text class="span">{{ D.addtime }}　　阅读{{ D.click }}</text>
      </view>
    </view>
    <view v-if="tjU.length > 0" :style="'--color:' + color + ';--rgbcolor:' + rgbcolor + ';'" class="detaiuser">
      <view v-for="(item, index) in tjU" :key="index" class="li">
        <navigator :url="'/pagesA/u/u?uid=' + item.uid" hoverClass="none">
          <image :src="item.photo_s" mode="aspectFill"></image>
          <view class="h5">{{ item.nickname }}</view>
          <view class="h5">{{ item.age }}</view>
        </navigator>
      </view>
      <view class="tj">
        缘分就在一瞬间
        <text class="btn3" @tap="kefuFn">联系客服牵线</text>
      </view>
    </view>
    <view class="detail_C">
      <rich-text :nodes="content" class="CC"></rich-text>
    </view>
    <view v-if="AGREE.flag == 1" class="detail_agree">
      第一次接受赞赏，亲，看着给啊
      <view class="button" @tap="agree_payFn">
        <text class="i ico"></text>
        <text class="font">{{ AGREE.num }}</text>
        <text class="font">赞赏</text>
      </view>
      <view v-if="AGREE.ulist.length > 0" class="ulist">
        <navigator v-for="(item, index) in AGREE.ulist" :key="index" :url="'/pagesA/u/u?uid=' + item.uid"
                   hoverClass="none">
          <image :src="item.photo_s" mode="aspectFill"></image>
        </navigator>
      </view>
    </view>
    <view v-if="agree_pay_show" class="mask2 alpha0_100">
      <view class="div_box big_normal agree_pay" style="--div_box_width: 80%; --div_box_height: 530rpx">
        <view class="close ico" @tap="kefu_closeFn"></view>
        <view class="h1left">选择赞赏金额</view>
        <view class="ul">
          <view v-for="(item, index) in AGREE.ifpay_num" :key="index" :data-money="item" class="li"
                @tap="agree_pay_numFn">
            <text class="b">{{ item }}</text>

            元
          </view>
        </view>
        <image :src="AGREE.ifpay_bg" mode="widthFix"></image>
      </view>
    </view>
    <view v-if="TJ.length > 0" class="detail_tj">
      <view class="dl">
        <view class="dt">
          推荐文章
          <navigator hoverClass="none" openType="reLaunch" url="article">更多</navigator>
        </view>
        <view v-for="(item, index) in TJ" :key="index" class="dd">
          <navigator :url="'/pagesA/article/article_detail?id=' + item.id" hoverClass="none">{{
              item.title
            }}
          </navigator>
        </view>
      </view>
    </view>
    <view v-if="BBS.length > 0 && D.ifbbs == 1" :style="'--color:' + color + ';'" class="detail_bbs">
      <view class="dl">
        <view class="dt">最新评论</view>
        <view v-for="(item, index) in BBS" :key="index" class="dd">
          <view class="nick div">
            <navigator :url="'/pagesAu/u?uid=' + item.uid" hoverClass="none">
              <image :src="item.photo_s" class="m" mode="aspectFill"></image>
            </navigator>
            <view class="b">
              <text class="font">{{ item.nickname }}</text>
              <image :src="item.grade_ico" class="ugrade1" mode="aspectFill"></image>
            </view>
            <view :class="'span ' + item.class" :data-id="item.id" :data-idx="index" @tap="agreeFn">
              <text :style="'display:' + item.agreefly + ';'" class="b agreefly">+1</text>
              <text class="font">{{ item.agree }}</text>
              <text class="i ico"></text>
            </view>
          </view>

          <view class="content div">{{ item.content }}</view>

          <view class="time div">{{ item.areatitle }} · {{ item.addtime }}</view>
        </view>
      </view>
    </view>
    <view v-if="D.ifbbs == 1" :style="'--color:' + color + ';'" class="detail_bbs_add">
      <navigator hoverClass="none" openType="switchTab" url="/pages/my/my">
        <image :src="D.cook_photo_s" mode="aspectFill"></image>
      </navigator>
      <view class="span" @tap="bbs_addFn">
        <text class="font ico"></text>
        <text class="font">写评论</text>
      </view>
      <text class="i ico" @tap="bbs_showFn">
        
        <text class="b">{{ D.bbsnum }}</text>
      </text>
      <button class="i ico" openType="share"></button>
    </view>
    <view v-if="div_bbs" class="mask2 alpha0_100">
      <view class="div_box big_normal div_bbs" style="--div_box_width: 82%; --div_box_height: 480rpx">
        <view class="close ico" @tap="kefu_closeFn"></view>
        <view class="div_title">随便说点什么</view>
        <form @submit="div_bbs_submitFn">
          <textarea class="textarea" name="content" placeholder="请文明发言~~"
                    placeholderClass="placeholder"></textarea>
          <button :style="'--color:' + color + ';--rgbcolor:' + rgbcolor + ';'" class="btn4 ico" formType="submit">
            提交评论
          </button>
        </form>
      </view>
    </view>
    <view v-if="kefushow" class="mask2 alpha0_100">
      <view class="div_box big_normal" style="--div_box_width: 70%; --div_box_height: 666rpx">
        <view class="close ico" @tap="kefu_closeFn"></view>
        <view class="truename">咨询客服</view>
        <view class="kf_wxpic">
          <image :showMenuByLongpress="true" :src="KEFU.wxpic"></image>
        </view>
        <view class="kf_text">长按识别二维码添加客服微信</view>
        <view class="kf_text">咨询客服1对1人工服务</view>
      </view>
    </view>
    <!-- parse <include src="../login.wxml"></include> -->
    <block>
      <view v-if="div_login" class="mask3 alpha0_100">
        <view
            class="div_box big_normal"
            style="--div_box_width: 82%; --div_box_height: 666rpx; background: -webkit-linear-gradient(top, #fde9ee 1%, #fff 150%); background-color: #fff"
        >
          <view :style="'border-color:rgba(' + rgbcolor + ',.2);'" class="m">
            <image mode="aspectFit" src="/static/res/img/photo_m.png"></image>
          </view>
          <view class="S22 B">登录后获得更精准推荐</view>
          <view class="loginagree">
            <checkbox-group @change="ifagreeFn">
              <label style="margin-left: -10rpx">
                <checkbox :style="'--color:' + color + ';'" value="1"></checkbox>
                <text class="C666 vmiddle">阅读并同意</text>
              </label>
            </checkbox-group>
            <navigator :style="'color:' + color" class="vmiddle" hoverClass="none"
                       url="/pagesA/about/law?kind=agreement">用户协议
            </navigator>
            <text class="C666 vmiddle">与</text>
            <navigator :style="'color:' + color + ';'" class="vmiddle" hoverClass="none"
                       url="/pagesA/about/law?kind=declara">隐私条款
            </navigator>
          </view>
          <button
              v-if="ifagree"
              :style="'--color:' + color + ';--rgbcolor:' + rgbcolor + ';width:73%'"
              class="btn5 W90_"
              openType="getPhoneNumber"
              @getphonenumber="getPhoneNumber"
          >
            <text>手机号快捷登录</text>
            <text :style="'color: ' + color + ';'">私密</text>
          </button>
          <button v-else :style="'--color:' + color + ';--rgbcolor:' + rgbcolor + ';width:73%'"
                  class="btn5" @tap="ifagree_passFn">
            <text>手机号快捷登录</text>
            <text :style="'color: ' + color + ';'">私密</text>
          </button>
          <view class="C666" @tap="back">
            <text style="border-bottom: #999 1px solid">暂不登录</text>
          </view>
        </view>
      </view>
    </block>
    <view v-if="backtop_flag" :style="'color:' + color" class="backtop fadeInUp" data-id="index" @tap="backtopFn">
      <text class="ico icon-backtop"></text>
      顶部
    </view>
    <view class="blank"></view>
  </view>
</template>
<script>
var t;
var a = require('../../@babel/runtime/helpers/defineProperty');
var i = require('../../res/www.a9a.cn.js');
var app = getApp();
export default {
  data() {
    return {
      nTitle: '婚恋学堂',
      fid: '',
      color: '',
      rgbcolor: '',
      backtop_flag: false,

      D: {
        title: '',
        logo: '',
        addtime: '',
        click: '',
        ifbbs: 0,
        cook_photo_s: '',
        bbsnum: ''
      },

      content: '',
      tjU: '',

      KEFU: {
        wxpic: ''
      },

      AGREE: {
        flag: 0,
        num: '',
        ulist: [],
        ifpay_num: [],
        ifpay_bg: ''
      },

      TJ: '',
      BBS: '',
      ios_ifpay: '',
      agree_pay_show: false,
      div_bbs: false,
      div_login: false,
      kefushow: false,
      ifagree: false,
      nTop: '',
      nHeight: '',
      pages: [],
      nTH: ''
    };
  },
  onLoad: function (t) {
    var that = this;
    this.setData({
      fid: t.id
    });
    uni.setNavigationBarTitle({
      title: that.nTitle
    });
    app.globalData.get_config('_ZEAI').then(function (t) {
      that.setData({
        color: app.globalData._ZEAI.color,
        rgbcolor: i.c16_rgb(app.globalData._ZEAI.color)
      });
    });
    app.globalData.get_navigationBarTopHeight(that);
    app.globalData.get_openid().then(function (t) {
      that.init();
    });
  },
  onPageScroll: function (t) {
    t.scrollTop > 100
        ? this.setData({
          backtop_flag: true
        })
        : this.setData({
          backtop_flag: false
        });
  },
  onShareAppMessage: function () {
    return {
      imageUrl: this.D.path_b,
      title: this.D.wxshareT,
      path: '/pagesA/article/article_detail?id=' + this.fid
    };
  },
  onShareTimeline: function () {
    return {
      imageUrl: this.D.path_b,
      title: this.D.wxshareT,
      query: 'id=' + this.fid,
      path: '/pagesA/article/article_detail'
    };
  },
  methods: {
    init: function () {
      var that = this;
      i.ifint(that.fid) ||
      uni.showModal({
        content: 'fid跑路了',
        confirmColor: that.color,
        confirmText: '朕知道了',
        showCancel: false,
        success: function (t) {
          uni.navigateBack();
        }
      });
      uni.showLoading({
        title: '玩命加载中...',
        mask: true
      });
      t = uni.getStorageSync('COOK_U');
      app.globalData.ajax({
        url: 'article.php',
        data: {
          submitok: 'article_detail',
          openid: t.openid,
          fid: that.fid
        },
        success: function (t) {
          if (1 == t.flag) {
            var e = i.escape2Html(t.D.content);
            that.setData({
              D: t.D,
              nTitle: t.D.nTitle,
              content: e,
              tjU: t.tjU,
              KEFU: t.KEFU,
              AGREE: t.AGREE,
              TJ: t.TJ,
              BBS: t.BBS,
              ios_ifpay: t.ios_ifpay
            });
          } else {
            uni.showToast({
              title: t.msg,
              icon: 'none',
              mask: true
            });
          }
          uni.hideLoading();
        }
      });
    },

    agree_payFn: function () {
      var that = this;
      app.globalData.chklogin().then(function (a) {
        if (a) {
          that.setData({
            agree_pay_show: true
          });
        } else {
          uni.navigateTo({
            url: '/pages/login/login'
          });
        }
      });
    },

    getPhoneNumber: function (t) {
      app.globalData.getPhoneNumber({
        e: t,
        url: '/pagesA/reg/reg'
      });
    },

    agree_pay_numFn: function (a) {
      this.setData({
        agree_pay_show: false
      });
      var that = this;
      var o = a.currentTarget.dataset.money;
      app.globalData.chklogin().then(function (a) {
        if (a) {
          1 != that.ios_ifpay.flag
              ? uni.getSystemInfo({
                success: function (a) {
                  if ('ios' == a.platform) {
                    uni.showModal({
                      title: '温馨提示',
                      content: that.ios_ifpay.tips,
                      confirmColor: that.color,
                      cancelText: '返回',
                      confirmText: '联系经纪人',
                      success: function (t) {
                        if (t.confirm) {
                          uni.redirectTo({
                            url: '/myPages/hongniang/hongniang'
                          });
                        } else {
                          if (t.cancel) {
                            uni.navigateBack();
                          }
                        }
                      }
                    });
                  } else {
                    app.globalData.pay({
                      data: {
                        submitok: 'article_detail_agree',
                        openid: t.openid,
                        fid: that.fid,
                        money: o
                      },
                      success: function () {
                        uni.showModal({
                          content: '支付成功，非常感谢您的支持！',
                          confirmColor: that.color,
                          confirmText: '返回',
                          showCancel: false,
                          success: function (t) {
                            that.init();
                          }
                        });
                      },
                      fail: function (t) {
                        t.this = that;
                        t.url = 'no';
                        i.sorry(t);
                      }
                    });
                  }
                }
              })
              : app.globalData.pay({
                data: {
                  submitok: 'article_detail_agree',
                  openid: t.openid,
                  fid: that.fid,
                  money: o
                },
                success: function () {
                  uni.showModal({
                    content: '支付成功，非常感谢您的支持！',
                    confirmColor: that.color,
                    confirmText: '返回',
                    showCancel: false,
                    success: function (t) {
                      that.init();
                    }
                  });
                },
                fail: function (t) {
                  t.this = that;
                  t.url = 'no';
                  i.sorry(t);
                }
              });
        } else {
          uni.navigateTo({
            url: '/pages/login/login'
          });
        }
      });
    },

    agreeFn: function (n) {
      var that = this;
      var s = n.currentTarget.dataset.idx;
      var c = n.currentTarget.dataset.id;
      var r = that.BBS[s].class;
      i.indexOf(r, 'ed') ||
      ((t = uni.getStorageSync('COOK_U')),
          app.globalData.ajax({
            url: 'article.php',
            data: {
              submitok: 'bbs_agree',
              id: c,
              fid: that.fid,
              openid: t.openid
            },
            success: function (t) {
              var e;
              1 == t.flag
                  ? that.setData(
                      (a((e = {}), 'BBS[' + s + '].agreefly', 'block'),
                          a(e, 'BBS[' + s + '].agree', parseInt(that.BBS[s].agree) + 1),
                          a(e, 'BBS[' + s + '].class', 'ed'),
                          e)
                  )
                  : ((t.this = that), (t.url = 'no'), i.sorry(t));
            }
          }));
    },

    bbs_showFn: function () {
      uni.pageScrollTo({
        scrollTop: 999999,
        duration: 300
      });
    },

    bbs_addFn: function () {
      var that = this;
      app.globalData.chklogin().then(function (a) {
        a
            ? that.setData({
              div_bbs: true
            })
            : uni.navigateTo({
              url: '/pages/login/login'
            });
      });
    },

    div_bbs_submitFn: function (a) {
      var that = this;
      var o = a.detail.value;
      app.globalData.empty(o.content)
          ? uni.showToast({
            title: '请输入评论内容',
            icon: 'none',
            mask: true
          })
          : uni.showModal({
            title: '',
            content: '确定提交么？\r\n以下情形话题将被删除或封号：\r\n《请勿留下任何形式联系方法》\r\n《请勿发表涉黄涉政言论》\r\n《不得辱骂或攻击他人》',
            confirmColor: that.color,
            cancelText: '取消',
            confirmText: '确定',
            success: function (a) {
              if (a.confirm) {
                uni.showLoading({
                  title: '正在保存',
                  mask: true
                });
                app.globalData.ajax({
                  url: 'article.php',
                  data: {
                    submitok: 'bbs_add',
                    openid: t.openid,
                    fid: that.fid,
                    content: o.content
                  },
                  success: function (t) {
                    uni.hideLoading();
                    1 == t.flag
                        ? uni.showModal({
                          content: t.msg,
                          confirmColor: that.color,
                          confirmText: '朕知道了',
                          showCancel: false,
                          success: function (t) {
                            that.setData({
                              div_bbs: false
                            });
                            that.init();
                          }
                        })
                        : ((t.this = that), (t.url = 'no'), i.sorry(t));
                  }
                });
              }
            }
          });
    },

    back: function () {
      this.setData({
        div_login: false
      });
    },

    backtopFn: function (t) {
      uni.pageScrollTo({
        scrollTop: 0,
        duration: 300
      });
    },

    kefuFn: function (t) {
      1 == this.D.ifps
          ? tt.navigateTo({
            url: '../about/about'
          })
          : this.setData({
            kefushow: true
          });
    },

    kefu_closeFn: function () {
      this.setData({
        kefushow: false,
        agree_pay_show: false,
        div_bbs: false
      });
    },

    ifagreeFn: function (t) {
      1 == t.detail.value
          ? this.setData({
            ifagree: true
          })
          : this.setData({
            ifagree: false
          });
    },

    ifagree_passFn: function () {
      uni.showToast({
        title: '请先点击同意《用户协议》和《隐私条款》',
        icon: 'none',
        mask: true,
        duration: 3000
      });
    }
  }
};
</script>
<style>
@import 'article_detail.css';
</style>
